package com.desay.pangoo.itmt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import com.desay.pangoo.common.lite.lang.web.CommonResponse;
import com.desay.pangoo.itmt.controller.vo.TechNewsVo;
import com.desay.pangoo.itmt.service.TechNewsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author uidq1163
 */

@RestController
@Api(tags = "技术信息")
@RequestMapping(value = "/tech/news")
public class TechNewsController {
	@Autowired
	private TechNewsService service;

	@PostMapping
	@ApiOperation(value = "添加信息", notes = "")
	public ResponseEntity<Object> create(@RequestBody TechNewsVo vo) {
		return new ResponseEntity<>(CommonResponse.success(service.create(vo)), HttpStatus.OK);
	}

	@PostMapping(value = "/faceBack")
	@ApiOperation(value = "反馈信息", notes = "")
	public ResponseEntity<Object> faceBack(@RequestBody TechNewsVo vo) {
		service.addFaceBack(vo);
		return new ResponseEntity<>(CommonResponse.success(), HttpStatus.OK);
	}

	@GetMapping
	@ApiOperation(value = "技术信息列表", notes = "")
	@ApiImplicitParams({ @ApiImplicitParam(name = "workGroupId", type = "string", value = "工作组id", paramType = "query"),
			@ApiImplicitParam(name = "pageNo", type = "int", required = true, value = "指定查询页数(1,2,3...)", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", type = "int", required = true, value = "每页数据数量", paramType = "query") })
	public ResponseEntity<Object> search(@RequestParam(required = false) Long workGroupId,
			@RequestParam Integer pageSize, @RequestParam Integer pageNo) {
		return new ResponseEntity<>(CommonResponse.success(service.getAll(workGroupId, pageSize, pageNo)),
				HttpStatus.OK);
	}

	@GetMapping(value = "/faceBack/{id}")
	@ApiOperation(value = "获取技术信息反馈列表", notes = "")
	public ResponseEntity<Object> getFaceBackList(@PathVariable(value = "id") Long id) {
		return new ResponseEntity<>(CommonResponse.success(service.getFaceBackList(id)), HttpStatus.OK);
	}

	@GetMapping(value = "/{id}")
	@ApiOperation(value = "获取技术信息", notes = "")
	public ResponseEntity<Object> getTechNews(@PathVariable(value = "id") Long id) {
		return new ResponseEntity<>(CommonResponse.success(service.getTechNews(id)), HttpStatus.OK);
	}

	@GetMapping(value = "/report")
	@ApiOperation(value = "技术信息汇总报告", notes = "获取指定时间范围内的技术报告总结信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "startDate", type = "string", required = true, value = "开始时间：yyyy-mm-dd", paramType = "query"),
			@ApiImplicitParam(name = "endDate", type = "string", value = "结束时间：yyyy-mm-dd", paramType = "query") })
	public ResponseEntity<Object> report(@RequestParam String startDate,
			@RequestParam(required = false) String endDate) {
		return new ResponseEntity<>(CommonResponse.success(service.report(startDate, endDate)), HttpStatus.OK);
	}
}
